package cn.bnuz.edu.liyang.wait_eat_what;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.stx.xhb.xbanner.XBanner;

import java.util.ArrayList;

public class MainPage extends AppCompatActivity {
    TextView textView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_page);

        //长按美食文本弹出菜单
        textView = (TextView) findViewById((R.id.thereT1));
        registerForContextMenu(textView);
        //点击人像按钮弹出登录界面
        ImageButton loginbutton = (ImageButton) findViewById(R.id.loginbuttom);
        loginbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainPage.this,Login.class);
                startActivity(intent);
            }
        });
        //点击事件
        ImageButton imageButton1 = (ImageButton)findViewById(R.id.foodbutton);
        imageButton1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainPage.this,Food.class);
                startActivity(intent);
            }
        });
        ImageButton imageButton2 = (ImageButton)findViewById(R.id.drinkbutton);
        imageButton2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainPage.this,Drink.class);
                startActivity(intent);
            }
        });
        ImageButton imageButton3 = (ImageButton)findViewById(R.id.championbutton);
        imageButton3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainPage.this,Best.class);
                startActivity(intent);
            }
        });

        //xbanner
        final XBanner mXBanner = (XBanner)findViewById(R.id.xbanner);

        final ArrayList images = new ArrayList<>();
        ArrayList titles = new ArrayList<>();
        images.add(R.drawable.xban0);
        images.add(R.drawable.xban1);
        images.add(R.drawable.xban2);


        mXBanner.loadImage(new XBanner.XBannerAdapter() {
            @Override
            public void loadBanner(XBanner banner, Object model, View view, int position) {
                Glide.with(MainPage.this).load(images.get(position)).into((ImageView) view);
            }
        });



        mXBanner.setOnItemClickListener(new XBanner.OnItemClickListener() {
            @Override
            public void onItemClick(XBanner banner, Object model, View view, int position) {
                Toast.makeText(MainPage.this,"点击了第"+position+"张图片\n",Toast.LENGTH_SHORT).show();

            }
        });

        mXBanner.setBannerData(images);


    }
}
